package com.aaa.sbms.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class UserSession {
    // 创建用户session
    public static HttpSession getUserSession () {

        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = (HttpServletRequest) requestAttributes.getRequest();
        return request.getSession();
    }

    // 保存session
    public static void saveUser (Object obj) {
        getUserSession().setAttribute("user",obj);
    }

    // 取出保存的session信息
    public static Object getUser() {
        return getUserSession().getAttribute("user");
    }
}
